package com.sfang.common.base.exception;

/**
 * @Desc
 * @Class TransTypeS
 * @Author Jimmy
 * @Date 0006 2017/4/6
 */
public enum SentinelExceptionType {
    SENTINEL_FLOW_ERROR(500427, "请求过于频繁，被限流了"),
    SENTINEL_DEGRADE_ERROR(500428, "请求过于频繁，被降级了"),
    SENTINEL_PARAM_FLOW_ERROR(500429, "热点数据请求过于频繁"),
    SENTINEL_SYSTEM_ERROR(500430, "请求过于频繁，触发系统限制"),
    SENTINEL_AUTHORITY_ERROR(500431, "授权规则不通过"),
    SENTINEL_UNKNOWN_ERROR(500450, "sentinel unknown exception");


    SentinelExceptionType(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    private Integer code;
    private String desc;

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public static SentinelExceptionType handleCode(String code) {
        if (code == null) return null;
        for (SentinelExceptionType types : SentinelExceptionType.values()) {
            if (types.getCode().equals(code))
                return types;
        }
        return null;
    }

    public static SentinelExceptionType handleDesc(String desc) {
        if (desc == null) return null;
        for (SentinelExceptionType types : SentinelExceptionType.values()) {
            if (types.getDesc().equals(desc))
                return types;
        }
        return null;
    }
}
